import { useEffect, useState } from 'react';
// 自定义hook必须以use开头
const useMousePositions = () => {
  const [positions, setPositions] = useState({x: 0, y: 0});
  useEffect(() => {
    console.log('add effect', positions.x);
    const updateMouse = (e: MouseEvent) => {
      setPositions({x: e.clientX, y: e.clientY})
    }
    document.addEventListener('mousemove', updateMouse)
    return () => {
      console.log('remove effect', positions.x);
      document.removeEventListener('mousemove', updateMouse)
    }
    // eslint-disable-next-line
  }, []);
  // 直接返回
  return positions;
}
export default useMousePositions;